﻿using System;
using System.Collections.Generic;
using System.Linq;
using Soundteller.Visual.Model;
using Soundteller.Visual.Model.Interfaces;
using Soundteller.Visual.Repositories.Interfaces;

namespace Soundteller.Visual.Repositories
{
    public class GraphicRepository : MemoryRepositoryBase, IGraphicRepository
    {
        public GraphicRepository(IMemoryContext context)
            : base(context)
        {
        }

        public GraphicBase GetByName(string name)
        {
            return Context.Graphics.SingleOrDefault(g => g.Name == name);
        }

        public void Add(GraphicBase graphic)
        {
            if (graphic == null) throw new ArgumentNullException("graphic");

            Context.Graphics.Add(graphic);
        }

        public IEnumerable<GraphicBase> GetByCategory(string category)
        {
            return Context.Graphics.Where(g => g.Categories.Contains(category)).ToList();
        }
    }
}
